$(function () {
    $("#jqGrid").jqGrid({
        url: '../injuryexpensereimbursement/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true,hidden:true },
			{ label: '员工姓名', name: 'name', index: 'name', width: 80 }, 			
			{ label: '身份证号', name: 'idno', index: 'idno', width: 80,hidden:true },
			{ label: '公司名称', name: 'company', index: 'company', width: 80 }, 			
			{ label: '公司id', name: 'companyId', index: 'company_id', width: 80,hidden:true },
			{ label: '部门', name: 'dept', index: 'dept', width: 80 }, 			
			{ label: '岗位名称', name: 'post', index: 'post', width: 80 }, 			
			{ label: '岗位id', name: 'postId', index: 'post_id', width: 80 ,hidden:true},
			{ label: '发票类型', name: 'invoiceType', index: 'invoice_type', width: 100 },
			{ label: '发票金额', name: 'invoiceMoney', index: 'invoice_money', width: 100 },
			{ label: '发票数量', name: 'invoiceQuantity', index: 'invoice_quantity', width: 100 },
			{ label: '报销提交日期', name: 'reimbursementSubmitDate', index: 'reimbursement_submit_date',width: 130, formatter:"date", formatoptions: {newformat:'Y-m-d'}  },
			{ label: '报销金额', name: 'reimbursementMoney', index: 'reimbursement_money', width: 100 },
			{ label: '伙食补助', name: 'hsbz', index: 'hsbz', width: 100 },
			{ label: '工亡待遇', name: 'gwdy', index: 'gwdy', width: 100 },
			{ label: '回款日期', name: 'hkrq', index: 'hkrq', width: 90, formatter:"date", formatoptions: {newformat:'Y-m-d'}  },
			{ label: '回款批次', name: 'hkpc', index: 'hkpc', width: 80 }, 			
			{ label: '事故发生时间', name: 'sgfssj', index: 'sgfssj', width: 120, formatter:"date", formatoptions: {newformat:'Y-m-d'} },
			{ label: '制表人', name: 'cusername', index: 'cusername', width: 80 }, 			
			{ label: '录入日期', name: 'cdate', index: 'cdate', width: 110, formatter:"date", formatoptions: {newformat:'Y-m-d'}  }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        shrinkToFit:false,
        autoScroll: false,

        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            dept: null,
            name: null
        },
		showList: true,
        showtable: false,
		title: null,
		injuryExpenseReimbursement: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
            vm.showtable=false;

            vm.title = "新增";
			vm.injuryExpenseReimbursement = {
				name:""
			};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.showtable=false;

            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.injuryExpenseReimbursement.id == null ? "../injuryexpensereimbursement/save" : "../injuryexpensereimbursement/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.injuryExpenseReimbursement),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../injuryexpensereimbursement/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../injuryexpensereimbursement/info/"+id, function(r){
                vm.injuryExpenseReimbursement = r.injuryExpenseReimbursement;
            });
		},
		reload: function (event) {
			vm.showList = true;
            vm.showtable=false;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    'name': vm.q.name, 'company': vm.q.company, 'post': vm.q.post,
                    'dept': vm.q.dept},
                page:page
            }).trigger("reloadGrid");
		},
        updateHk: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable=true;
            vm.title = "修改回款";
            vm.getInfo(id);
        },
        popPage: function(){
            utils.popGrid();
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择员工",
                area: ['800px', '450px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#popLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var grid = $("#popGrid");
                    var rowKey = grid.getGridParam("selrow");
                    if(!rowKey){
                        alert("请选择一条记录");
                        return ;
                    }
                    var rowData=grid.jqGrid("getRowData",rowKey);
                    vm.unemploymentInsuranceManagement.name=rowData.name;
                    vm.unemploymentInsuranceManagement.idno=rowData.idno;
                    vm.unemploymentInsuranceManagement.company=rowData.company;
                    vm.unemploymentInsuranceManagement.companyid=rowData.companyId;
                    // vm.unemploymentInsuranceManagement.dept=rowData.department;
                    vm.unemploymentInsuranceManagement.age=rowData.age;
                    var sex=rowData.sex;
                    if(sex=='男'){
                        sex="0";
                    }else if(sex=='女'){
                        sex="1";
                    }
                    vm.unemploymentInsuranceManagement.sex=sex;
                    vm.unemploymentInsuranceManagement.telephone=rowData.telphone;

                    //alert(JSON.stringify( vm.safetyEducationManagement));


                    layer.close(index);
                }
            });
        },
	}
});